package com.example.br;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.gsm.SmsMessage;

/**
 * Created by 居伦昶 on 2018/6/9.
 */

public class SMSReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        System.out.print("receiver message");

        //短信的转化显示
        Bundle bundle=intent.getExtras();//接受intent对象的数据
        Object[] myobjpdus=(Object[]) bundle.get("pdus");//在bundle对象中有一个pdus的属性，它的值是object数组
        android.telephony.SmsMessage[] messages =new android.telephony.SmsMessage[myobjpdus.length];
        //创建一个smsmessage类型数组
        System.out.print(messages.length);
        for(int i=0;i<myobjpdus.length;i++){
            messages[i]= android.telephony.SmsMessage.createFromPdu((byte[])myobjpdus[i]);
            System.out.print(messages[i].getDisplayMessageBody());
        }
    }
}
